package com.yunzheng.studyLeaveSystem.modules.admin.show.students.servlet;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yunzheng.studyLeaveSystem.modules.admin.show.students.entity.adjuster;
import com.yunzheng.studyLeaveSystem.modules.admin.show.students.service.AdjustService;
import com.yunzheng.studyLeaveSystem.modules.response.ResponseWrapper;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
/*
*将本周研学调整情况的数据传递给前端
*/
@WebServlet(name = "students AdjustServlet",value = "/students_AdjustServlet")
    public class SearchAdjustServlet extends HttpServlet {
        @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求实体数据
        BufferedReader reader = request.getReader();
        String readLine = reader.readLine();
        //将json字符转化为java对象
        JSONObject jsonObject = JSON.parseObject(readLine);
        String name = jsonObject.getString("name");
        AdjustService adjustService = new AdjustService();
        List<adjuster> InformationList;
        try {
            InformationList = adjustService.showInformation(name);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        ResponseWrapper responseWrapper = ResponseWrapper.Success(InformationList);
        String s = JSON.toJSONString(responseWrapper);
        PrintWriter writer = response.getWriter();
        writer.println(s);
        System.out.println(s);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
